/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "pChart"
 * by Craig @ There4 Development

 * --------------------------------------------------------------------
 * @example $(function(){$(img).pChart();});
 * --------------------------------------------------------------------
 */

(function($) {
 
  $.fn.pChart = function(settings) {
    var config = {
          'Action': 'GetImageMap'
          };
          
    if (settings) config = $.extend(config, settings);
    
    this.each(function() {
      $(this).load(function(){
        var map_id = $(this).attr('id');
        var map_url = $(this).attr('src') + "&Action=" + config.Action;
        $.ajax({
          type: "GET",
          url: map_url,
          dataType: "text",
          success: function (data) {
            var new_map = data;
            $("body").append(new_map);
            $('#' + map_id).attr('usemap',"#map_" + map_id);
            $('#map_'+map_id+' area').each(function() {
              $(this).qtip({
                content: $(this).attr('alt'),
                tip: true,
                position: {
                    corner: {
                       target: 'rightTop',
                       tooltip: 'leftBottom'
                    }
                },
                style: {
                  border: {
                     width: 2,
                     radius: 5
                  },
                  padding: 4, 
                  textAlign: 'center',
                  tip: true,
                  name: 'dark'
                }
              });
            });
          },
          error: function () {
            // could be used to retry
          }
        }); // ajax()
      }); // load() 
    }); // this.each() 
    return this;
   };
 
 })(jQuery);